from django.contrib.auth.models import User
from rest_framework import serializers,pagination
from info_sys.models import Supplier, Buyer, Item, Order, OrderItem, goodItem, goodVerfiyImage
import json

class BuyerSerializer(serializers.ModelSerializer):
    full_name = serializers.ReadOnlyField()
    nikename = serializers.ReadOnlyField()
    email = serializers.ReadOnlyField()
    class Meta:
        model = Buyer
        fields = ('id', 'phone', 'nikename', 'email', 'openid', 'full_name', 'is_verify',
                  'province', 'city', 'zone', 'street','address')

class SupplierSerializer(serializers.ModelSerializer):
    boss_name = serializers.ReadOnlyField()
    nikename = serializers.ReadOnlyField()
    email = serializers.ReadOnlyField()
    class Meta:
        model = Supplier
        fields = ('id', 'company_name', 'nikename', 'email', 'openid', 'boss_name', 'phone', 'is_verify',
                  'province','city', 'zone', 'street', 'address')


class ItemSerializer(serializers.ModelSerializer):
    class Meta:
        model = Item
        fields = ('id', 'name', 'content', 'sup_type', 'is_deleted')

class OrderItemSerializer(serializers.ModelSerializer):
    class Meta:
        model = OrderItem
        fields = ('id', 'item', 'count')


class OrderSerializer(serializers.ModelSerializer):
    order_items = OrderItemSerializer(many=True, read_only=True)
    buyer_name = serializers.ReadOnlyField()
    buyer_phone = serializers.ReadOnlyField()
    buyer_address = serializers.ReadOnlyField()
    buyer_zone = serializers.ReadOnlyField()
    content_plus = serializers.ReadOnlyField()
    class Meta:
        model = Order
        fields = ('id', 'buyer_name', 'buyer_phone', 'buyer_name', 'buyer_zone', 'buyer_address', 'content_plus',
                  'is_verify',  'is_deleted',  'updated', 'created', 'order_items')

class goodImgSerializer(serializers.ModelSerializer):
    class Meta:
        model = goodVerfiyImage
        fields = ('id', 'name', 'my_img', 'is_verify')

class goodItemSerializer(serializers.ModelSerializer):
    good_img = goodImgSerializer(many=True, read_only=True)
    supplier_name = serializers.ReadOnlyField()
    supplier_company_name = serializers.ReadOnlyField()
    supplier_phone = serializers.ReadOnlyField()
    supplier_address = serializers.ReadOnlyField()
    supplier_zone = serializers.ReadOnlyField()
    content_plus = serializers.ReadOnlyField()
    class Meta:
        model = goodItem
        fields = ('id', 'name', 'supplier_company_name', 'supplier_name', 'supplier_phone', 'supplier_address',
                  'supplier_zone', 'content_plus', 'is_verify', 'is_deleted', 'sup_type', 'updated',
                  'created', 'good_img')